package me.aartikov.flowscreenswitchersample.ui;

import me.aartikov.alligator.Navigator;
import me.aartikov.alligator.annotations.RegisterScreen;
import me.aartikov.alligator.helpers.MiFraction;
import me.aartikov.flowscreenswitchersample.ResourceTable;
import me.aartikov.flowscreenswitchersample.SampleApplication;
import me.aartikov.flowscreenswitchersample.screens.InnerScreen;
import me.aartikov.flowscreenswitchersample.screens.TestFlow2Screen;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

@RegisterScreen(InnerScreen.class)
public class InnerMiFraction extends MiFraction {
    Text mCounterTextView;

    Button mForwardButton;

    Button mForwardFlowButton;


    private Navigator mNavigator = SampleApplication.getNavigator();

    @Override
    protected void setInitialFragmentIfRequired() {

    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        mNavigator = SampleApplication.getNavigator();
    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        ComponentContainer componentContainer = (ComponentContainer) scatter.parse(ResourceTable.Layout_mifraction_inner, null, false);
        mCounterTextView = (Text) componentContainer.findComponentById(ResourceTable.Id_counter_text_view);
        mForwardButton = (Button) componentContainer.findComponentById(ResourceTable.Id_forward_button);
        mForwardFlowButton = (Button) componentContainer.findComponentById(ResourceTable.Id_forward_flow_button);


        InnerScreen screen = SampleApplication.getScreenResolver().getScreen(this);
        int counter = screen.getCounter();
        mCounterTextView.setText(getString(ResourceTable.String_counter_template, counter));
        mForwardButton.setClickedListener(v -> mNavigator.goForward(new InnerScreen(counter + 1, getParentId(), getGouptag().toString())));
        mForwardFlowButton.setClickedListener(view1 -> mNavigator.goForward(new TestFlow2Screen(ResourceTable.Id_flow_fragment_container, getFractionAbility().toString())));
        return componentContainer;
    }

    @Override
    protected void onActive() {
        super.onActive();
    }
}
